// 引入Sequelize模块
const Sequelize = require('sequelize');
// 引入数据库实例
const db = require('../db');
const user = require('./user');

// 一级分类model
const fonts = db.define('fonts', {
    // 主键
    id: {
        type: Sequelize.STRING(10),
        allowNull: false,
        unique: true,
        primaryKey: true
    },

    fileName: {
        type: Sequelize.STRING(50),
        allowNull: false,
    },

    fileUrl: {
        type: Sequelize.STRING(100),
        allowNull: true,
        defaultValue: 0,
    },

    fontName: {
        type: Sequelize.STRING(50),
    },

    fontValue: {
        type: Sequelize.STRING(50),
    },

    createdAt: {
        type: Sequelize.DATE,
        get() {
            const rawValue = this.getDataValue('createdAt');
            return dateFormat(rawValue, 'yyyy-mm-dd HH:MM:ss');
        }
    },

    updatedAt: {
        type: Sequelize.DATE,
        get() {
            const rawValue = this.getDataValue('updatedAt');
            return dateFormat(rawValue, 'yyyy-mm-dd HH:MM:ss');
        }
    }
}, {
    // 是否支持驼峰
    underscored: false,
    // MySQL数据库表名
    tableName: 'fonts',
});
(async () => {
    fonts.sync({
        alter: true
    });

    //console.log("字体库同步成功")
})();
/***一级分类 结束 */

// 一级分类model
const postType = db.define('postType', {
    // 主键
    id: {
        type: Sequelize.STRING(10),
        allowNull: false,
        unique: true,
        primaryKey: true
    },

    name: {
        type: Sequelize.STRING(50),
        allowNull: false,
    },

    topicImage: {
        type: Sequelize.STRING(100),
        allowNull: true,
        defaultValue: 0,
    },

    topicPath: {
        type: Sequelize.STRING(100),
    },

    bclazzs: {
        type: Sequelize.JSON,
        comment: "子类"
    },

    createdAt: {
        type: Sequelize.DATE,
        get() {
            const rawValue = this.getDataValue('createdAt');
            return dateFormat(rawValue, 'yyyy-mm-dd HH:MM:ss');
        }
    },

    updatedAt: {
        type: Sequelize.DATE,
        get() {
            const rawValue = this.getDataValue('updatedAt');
            return dateFormat(rawValue, 'yyyy-mm-dd HH:MM:ss');
        }
    }
}, {
    // 是否支持驼峰
    underscored: false,
    // MySQL数据库表名
    tableName: 'postType',
});
(async () => {
    postType.sync({
        alter: true
    });

    //console.log("教程同步成功")
})();
/***一级分类 结束 */


// 二级分类model
const postTag = db.define('postTag', {
    // 主键
    flag: {
        type: Sequelize.STRING(1),
    },

    remark: {
        type: Sequelize.STRING(50),
    },

    id: {
        type: Sequelize.STRING(10),
        allowNull: false,
        unique: true,
        primaryKey: true
    },

    name: {
        type: Sequelize.STRING(100),
    },
    sort: {
        type: Sequelize.INTEGER,
    },
    icon: {
        type: Sequelize.STRING(100),
    },
    icon2: {
        type: Sequelize.STRING(100),
    },
    posterStatus: {
        type: Sequelize.STRING(100),
    },
    printStatus: {
        type: Sequelize.STRING(100),
    },

    topicImage: {
        type: Sequelize.STRING(100),
    },
    topicPath: {
        type: Sequelize.STRING(100),
    },
    topicFlag: {
        type: Sequelize.STRING(1),
    },

    tagList: {
        type: Sequelize.JSON,
    },
    createdAt: {
        type: Sequelize.DATE,
        get() {
            const rawValue = this.getDataValue('createdAt');
            return dateFormat(rawValue, 'yyyy-mm-dd HH:MM:ss');
        }
    },

    updatedAt: {
        type: Sequelize.DATE,
        get() {
            const rawValue = this.getDataValue('updatedAt');
            return dateFormat(rawValue, 'yyyy-mm-dd HH:MM:ss');
        }
    }
}, {
    // 是否支持驼峰
    underscored: false,
    // MySQL数据库表名
    tableName: 'postTag',
});
(async () => {
    postTag.sync({
        alter: true
    });

    //console.log("二级分类同步成功")
})();
/***二级分类 结束 */


// 海报model
const poster = db.define('poster', {
    id: {
        type: Sequelize.STRING(10),
        allowNull: false,
        unique: true,
        primaryKey: true
    },

    type: {
        type: Sequelize.STRING(1),
    },
    sort: {
        type: Sequelize.INTEGER,
    },
    thumbnail: {
        type: Sequelize.STRING(100),
    },
    background: {
        type: Sequelize.STRING(100),
    },
    printBackground: {
        type: Sequelize.STRING(100),
    },
    width: {
        type: Sequelize.INTEGER,
    },

    height: {
        type: Sequelize.INTEGER,
    },
    rid: {
        type: Sequelize.STRING(10),
    },
    rname: {
        type: Sequelize.STRING(50),
    },

    typeId: {
        type: Sequelize.STRING(50),
    },
    tagId: {
        type: Sequelize.STRING(50),
    },

    typeName: {
        type: Sequelize.STRING(50),
    },

    sizeId: {
        type: Sequelize.STRING(50),
    },

    sizeName: {
        type: Sequelize.STRING(50),
    },
    keyWord: {
        type: Sequelize.STRING(200),
    },
    isChoice: {
        type: Sequelize.STRING(50),
    },
    isRecomm: {
        type: Sequelize.STRING(50),
    },
    isTemplateGroup: {
        type: Sequelize.STRING(50),
    },
    isParent: {
        type: Sequelize.STRING(50),
    },
    pid: {
        type: Sequelize.STRING(50),
    },

    rowCount: {
        type: Sequelize.STRING(50),
    },
    tips: {
        type: Sequelize.STRING(50),
    },
    tipsValue: {
        type: Sequelize.STRING(50),
    },
    flag: {
        type: Sequelize.STRING(50),
    },
    heartColor: {
        type: Sequelize.STRING(50),
    },
    isMainSize: {
        type: Sequelize.STRING(50),
    },
    mainSizeId: {
        type: Sequelize.STRING(50),
    },
    members: {
        type: Sequelize.JSON,
    },
    textElements: {
        type: Sequelize.JSON,
    },
    picElements: {
        type: Sequelize.JSON,
    },
    printSizes: {
        type: Sequelize.STRING(50),
    },
    elements: {
        type: Sequelize.JSON,
    },
    calendarId: {
        type: Sequelize.STRING(50),
    },
    colors: {
        type: Sequelize.STRING(50),
    },
    thickDates: {
        type: Sequelize.STRING(50),
    },
    monthTime: {
        type: Sequelize.STRING(50),
    },

    createdAt: {
        type: Sequelize.DATE,
        get() {
            const rawValue = this.getDataValue('createdAt');
            return dateFormat(rawValue, 'yyyy-mm-dd HH:MM:ss');
        }
    },

    updatedAt: {
        type: Sequelize.DATE,
        get() {
            const rawValue = this.getDataValue('updatedAt');
            return dateFormat(rawValue, 'yyyy-mm-dd HH:MM:ss');
        }
    }
}, {
    // 是否支持驼峰
    underscored: false,
    // MySQL数据库表名
    tableName: 'poster',
});
(async () => {
    /*poster.sync({
        alter: true
    });*/

    //console.log("海报同步成功")
})();
/***二级分类 结束 */


// 海报model
const userPoster = db.define('userPoster', {
    id: {
        type: Sequelize.STRING(20),
        allowNull: false,
        unique: true,
        primaryKey: true
    },

    posterId: {
        type: Sequelize.STRING(10),
    },
    dragBg: {
        type: Sequelize.JSON,
    },
    dragList: {
        type: Sequelize.JSON,
    },
    parent: {
        type: Sequelize.STRING(20),
    },

    createdAt: {
        type: Sequelize.DATE,
        get() {
            const rawValue = this.getDataValue('createdAt');
            return dateFormat(rawValue, 'yyyy-mm-dd HH:MM:ss');
        }
    },

    updatedAt: {
        type: Sequelize.DATE,
        get() {
            const rawValue = this.getDataValue('updatedAt');
            return dateFormat(rawValue, 'yyyy-mm-dd HH:MM:ss');
        }
    }
}, {
    // 是否支持驼峰
    underscored: false,
    // MySQL数据库表名
    tableName: 'userPoster',
});
/*(async () => {
    userPoster.sync({
        alter: true
    });

    console.log("用户作品海报同步成功")
})();*/
/***用户作品海报 结束 */

module.exports = {
    postType,
    postTag,
    poster,
    fonts,
    userPoster
};
